package com.pw.study.flink.source

import java.util.Properties

import org.apache.flink.api.common.serialization.SimpleStringSchema
import org.apache.flink.streaming.api.TimeCharacteristic
import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer011

object KafkaSource {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)
    env.setParallelism(1)
    val properties = new Properties()
    properties.setProperty("bootstrap.servers", "hadoop102:9092,hadoop103:9092,hadoop104:9092")
    properties.setProperty("group.id", "KafkaGroupName")
    properties.setProperty("auto.offset.reset", "latest")
    properties.setProperty("key.deserializer", "import org.apache.kafka.common.serialization.StringDeserializer")
    properties.setProperty("value.deserializer", "import org.apache.kafka.common.serialization.StringDeserializer")
    val dsKafka: DataStream[String] = env.addSource(new FlinkKafkaConsumer011[String]("topic_sensor", new SimpleStringSchema(), properties))

    dsKafka.print("kafka:")
    env.execute("kafka")
  }
}
